<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<title></title>
		<link href="../css/mui.min.css" rel="stylesheet" />
		<link rel="stylesheet" href="../css/together.css" />
		<link rel="stylesheet" type="text/css" href="../css/indexcss.css" />
		
		<style type="text/css">
			
			
			
		</style>
	</head>
	<body>
		<header class="mui-bar mui-bar-nav m_barC">
		    <h1 class="mui-title">我的书籍</h1>
		</header>
		<div id="refreshContainer" class="mui-content mui-scroll-wrapper">
		    <div class="mui-scroll ">
		
		<!--
        	作者：592176224@qq.com
        	时间：2019-03-28
        	描述：
			<div class="hdiv m_barC ">
					<div class="hdivleft"></div>
					<div class="hdivcontent">我的书籍</div>
					<div class="hdivright mui-icon mui-icon-extra mui-icon-extra-sweep" id="scan"></div>
			</div>
        -->
				<div class="ws_content ws_make flex-jcfs-aicent-fwwrap" id="ulmain">

				</div>
			
			<div class="findContent"></div>
		</div>	
		</div>		
		<script src="../js/jquery.min.js"></script>					
		<script src="../js/mui.min.js"></script>
		<script src="../js/mui.lazyload.js"></script>
		<script src="../js/mui.lazyload.img.js"></script>
		<script src="../js/mui.enterfocus.js"></script>
		<script src="../js/req.js"></script>
		<script src="../js/util.js"></script>
		<script src="../js/muishow.js" type="text/javascript" charset="utf-8"></script>
		<script type="text/javascript">
			var page = 1;
			
			window.onload = function(){
				mui.init({
						  pullRefresh : {
						    container:"#refreshContainer",//下拉刷新容器标识，querySelector能定位的css选择器均可，比如：id、.class等
						    down : {
						      height:50,//可选,默认50.触发下拉刷新拖动距离,
						      auto: false,//可选,默认false.首次加载自动下拉刷新一次
						      contentdown : "下拉可以刷新",//可选，在下拉可刷新状态时，下拉刷新控件上显示的标题内容
						      contentover : "释放立即刷新",//可选，在释放可刷新状态时，下拉刷新控件上显示的标题内容
						      contentrefresh : "正在刷新...",//可选，正在刷新状态时，下拉刷新控件上显示的标题内容
						      callback :function (){
						      		console.log("下拉")
						      		page = 1;
						      		getbooks();
						      		mui('#refreshContainer').pullRefresh().endPulldownToRefresh();
						      }
						    },
						  }
						});
				getbooks();
			}
			
			function getbooks() {
						let data = {
							url: "/api/Book/book_list",
							data: {
								access_token: acctoken() || "",
								page: page,
							}
						}
						ajax(data, function(res) {
							console.log("文章数据", res);
							if(res.code == -1) {
								mui.toast(res.message);
							}
							if(res.code == 1) {
								setbooks(res.data);

							}
						});
					}
			
			function setbooks(list){
				
				let str = '';
				if(list.length > 0 ){
					list.forEach(function(item,index){
						str += '<div class="mui-card-content ws_card_con">' +
						'<div class="ws_card_authority" onclick="delbook(' + item.id + ')">'+
						'<i class="mui-icon mui-icon-closeempty"></i></div>' +
						'<h1 class="ws_card_title">' + item.title + '</h1> ';
						var num = getmath();   
						str += '<img src="../bookbj/book-bj'+num+'.png" onclick="gobook(' + item.id + ')"/> ' +
						'<a class="ws_card_content">文章' + (index+1) + '篇</a>' +
						'<a class="ws_card_members">成员' + item.users_list.length + '个</a></div>';
					})
					if(list.length > 10) {
						g("footlistdiv").innerHTML = '<button onclick="addbooks()" type="button" class="butclass">加载更多</button>';
					}
				}else{
					str += '<div class="nolistdiv">暂无数据</div>';
				}
				g("ulmain").innerHTML = str;
				
			}
			function delbook(bookid) {
						mui.confirm("是否确定删除？", "", ["取消", "确定"], function(e) {
							if(e.index == 1) {
								console.log("shanchu");
								let data = {
									url: "/api/Book/del_book",
									data: {
										access_token: acctoken(),
										bid: bookid,
									}
								}
								ajax(data, function(res) {
									console.log(res)
									if(res.code == 1) {
										mui.toast("书籍删除成功");
										getbooks();
									}
								})
							}
						})
					}
			
			function addbooks(){
				page++;
				getbooks();
			}
			
			function gobook(id) {
						mui.openWindow({
							url: '../write_together/books_detas.html?bid=' + id,
							id: 'books_detas',
						});
					}
			
		</script>
	</body>
</html>
